/**
 * Copyright (c) 2015-2030 by Beijing Yanlight Co., Ltd.
 * All rights reserved.
 */
package com.yanlight.support.alipay;

import com.yanlight.Constants;
import com.yanlight.support.PropertiesHolder;
import com.yanlight.type.PayType;

/**
 * @author haolw
 * @time 2017/07/21
 */
public abstract class AlipayConstants {
    public static final String AUTH_USER_SCOPE = "auth_user";// 获取用户信息、网站支付宝登录
    public static final String AUTH_BASE_SCOPE = "auth_base";// 用户信息授权
    public static final String AUTH_ECARD_SCOPE = "auth_ecard";// 商户会员卡
    public static final String AUTH_INVOICE_INFO_SCOPE = "auth_invoice_info";// 支付宝闪电开票
    public static final String AUTH_PUC_CHARGE_SCOPE = "auth_puc_charge";// 生活缴费
    public static final String AUTHORIZE_URL = "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm";
    public static final String memberAuthCallbackUrl = "/alipay/memberAuth";

    public static final String NOTIFY_HOST = PropertiesHolder.get("trade.notify.host");
    public static final String gateway = PropertiesHolder.get("alipay.gateway");
    public static final String appId = PropertiesHolder.get("alipay.appId");
    public static final String partnerId = PropertiesHolder.get("alipay.partnerId");
    public static final String NOTIFY_PAY_URL = "/order/notifyPay/";
    public static final String privateKey = PropertiesHolder.get("alipay.privateKey");
    public static final String publicKey = PropertiesHolder.get("alipay.publicKey");

    public static final String mchAppId = PropertiesHolder.get("alipay.mch.appId");
    public static final String mchPrivateKey = PropertiesHolder.get("alipay.mch.privateKey");

    public static final String mchCertPath = PropertiesHolder.get("alipay.mch.certPath");
    public static final String mchPublicCertPath = PropertiesHolder.get("alipay.mch.publicCertPath");
    public static final String mchRootCertPath = PropertiesHolder.get("alipay.mch.rootCertPath");


    public static final String AUTH_GRANTTYPE_CODE = "authorization_code";
    public static final String AUTH_GRANTTYPE_REFRESH = "refresh_token";
    public static final String timeoutExpress = "5m";
    public static final String bodySuffix = "，订单号：";

    public static String getMemberAuthCallbackUrl() {
        return Constants.HOST + memberAuthCallbackUrl;
    }

    public static String getNotifyUrl(Integer companyId) {
        StringBuilder builder = new StringBuilder(16);
        builder.append(NOTIFY_HOST);
        builder.append(NOTIFY_PAY_URL);
        builder.append(companyId);
        builder.append(Constants.SLASH);
        builder.append(PayType.ALIPAY.getType());
        return builder.toString();
    }

    public static String getBody(String name, String tradeNo) {
        return name.concat(bodySuffix).concat(tradeNo);
    }
}
